﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace NoSPD_WebFeature
{
    public class NoSPDWebPropertyFeatureReceiver : SPFeatureReceiver
    {
        private object propertyKey = "vti_disablewebdesignfeatures2";
        private object propertyValue = "wdfopensite";

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb web = (SPWeb)properties.Feature.Parent;
            if (web.AllProperties.ContainsKey(propertyKey))
            {
                web.AllProperties[propertyKey] = propertyValue;
                web.Update();
            }
            else
            {
                web.AllProperties.Add(propertyKey, propertyValue);
                web.Update();
            }

            web.Dispose();
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            SPWeb web = (SPWeb)properties.Feature.Parent;
            if (web.AllProperties.ContainsKey(propertyKey))
            {
                web.AllProperties.Remove(propertyKey);
                web.Update();
            }
            web.Dispose();
        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
            /// Not Implemented
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
            /// Not Implemented
        }
    }
}
